#include "SerialServo.h"



alarm_threshold threshold;
extern int position_array[5];
extern int temperature_array[5];
extern int volatge_array[5];
//校验和
char LobotCheckSum(char buf[])
{
  int i;
  char check;
  uint16_t temp = 0;
  for (i = 2; i < buf[3] + 2; i++) {
    temp += buf[i];
  }
  temp = ~temp;
  check = (char)temp;
  return check;
}

//温度阈值读取
void LobotSerialServoReadTempLimit(uart_port_t uart_num)
{
//55 55 01 03 19 E2
unsigned char byte_hex;
unsigned char *p;
p = &byte_hex; 
char buf[7];

byte_hex = 0x55;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
byte_hex = 0x55;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
byte_hex = 0x01;
uart_write_bytes(uart_num, (const char*)p, 1);
byte_hex = 0x03;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
byte_hex = 0x19;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
byte_hex = 0xE2;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
uart_flush(uart_num);  

//串口读取
uart_read_bytes(uart_num, (uint8_t*)buf, 7, 100 / portTICK_PERIOD_MS);
uart_flush(uart_num); 
//uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
uart_flush(UART0_UX); 

threshold.temp_limit = buf[5];
printf("temp_limit= %d\n", threshold.temp_limit);
// printf("temp_limit= %d\n", buf[5]);

}

void LobotSerialServoReadVinLimit(uart_port_t uart_num)
{
   //55 55 01 03 19 E2
unsigned char byte_hex;
unsigned char *p;
p = &byte_hex; 
char buf[10];

byte_hex = 0x55;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
byte_hex = 0x55;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
byte_hex = 0x01;
uart_write_bytes(uart_num, (const char*)p, 1);
byte_hex = 0x03;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
byte_hex = 0x17;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
byte_hex = 0xE4;
uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
uart_flush(uart_num);  

//串口读取
uart_read_bytes(uart_num, (uint8_t*)buf, 10, 100 / portTICK_PERIOD_MS);
uart_flush(uart_num); 
//uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
uart_flush(UART0_UX); 

threshold.voltage_low = (float)(BYTE_TO_HW(buf[6], buf[5])*0.001);
printf("vol_limit_l= %d\n", BYTE_TO_HW(buf[6], buf[5]));
threshold.voltage_high = (float)(BYTE_TO_HW(buf[8], buf[7])*0.001);
printf("vol_limit_h= %d\n", BYTE_TO_HW(buf[8], buf[7]));


}



//控制舵机转动
void LobotSerialServoMove(uart_port_t uart_num,  uint8_t id, int16_t position, uint16_t time)
{
  char buf[10];
  if(position < 0)
    position = 0;
  if(position > 1000)
    position = 1000;
  buf[0] = buf[1] = LOBOT_SERVO_FRAME_HEADER;
  buf[2] = id;
  buf[3] = 7;
  buf[4] = LOBOT_SERVO_MOVE_TIME_WRITE;
  buf[5] = GET_LOW_BYTE(position);
  buf[6] = GET_HIGH_BYTE(position);
  buf[7] = GET_LOW_BYTE(time);
  buf[8] = GET_HIGH_BYTE(time);
  buf[9] = LobotCheckSum(buf);
  uart_write_bytes(uart_num, (const char*)buf, 10);   /* 写数据 */
  uart_write_bytes(UART0_UX, (const char*)buf, 10);
}


//读取舵机位置
void LobotSerialServoReadPosition(uart_port_t uart_num)
{

  unsigned char byte_hex;
  unsigned char *p;
  p = &byte_hex; 
  char buf[8];
  //55 55 01 03 1C DF
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x01;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1C;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDF;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  //串口读取
  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 

  position_array[0] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
  printf("position_array[0] = %d\n", position_array[0]);



//55 55 02 03 1C DE
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x02;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1C;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDE;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  position_array[1] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
  printf("position_array[1] = %d\n", position_array[1]);
  //55 55 03 03 1C DD
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1C;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDD;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  position_array[2] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
  printf("position_array[2] = %d\n", position_array[2]);

  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x04;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1C;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDC;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  position_array[3] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
  printf("position_array[3] = %d\n", position_array[3]);

  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x05;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1C;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDB;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  //if(buf[0]==buf[1]==0x55&&buf[7]==LobotCheckSum(buf))
  //{
    uart_flush(uart_num); 
    //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
    uart_flush(UART0_UX); 
    position_array[4] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
    printf("position_array[4] = %d\n", position_array[4]);

  //}



}

//读取电压
void LobotSerialServoReadVin(uart_port_t uart_num)
{
  unsigned char byte_hex;
  unsigned char *p;
  p = &byte_hex; 
  char buf[8];
  //55 55 01 03 1C DF
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x01;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1B;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xE0;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  volatge_array[0] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
  printf("volatge_array[0] = %d\n", volatge_array[0]);
//55 55 02 03 1C DE
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x02;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1B;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDF;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  volatge_array[1] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
  printf("volatge_array[1] = %d\n", volatge_array[1]);
  //55 55 03 03 1C DD
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1B;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDE;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  volatge_array[2] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
  printf("volatge_array[2] = %d\n", volatge_array[2]);

  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x04;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1B;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDD;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  volatge_array[3] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
  printf("volatge_array[3] = %d\n", volatge_array[3]);

  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x05;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1B;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDC;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  volatge_array[4] = (int16_t)BYTE_TO_HW(buf[6], buf[5]);
  printf("volatge_array[4] = %d\n", volatge_array[4]);
}

//温度
void LobotSerialServoReadTemp(uart_port_t uart_num)
{
  unsigned char byte_hex;
  unsigned char *p;
  p = &byte_hex; 
  char buf[7];
  //55 55 01 03 1C DF
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x01;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1A;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xE1;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  temperature_array[0] = buf[5];
  printf("temperature_array[0] = %d\n", temperature_array[0]);

  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x02;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1A;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xE0;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  temperature_array[1] = buf[5];
  printf("temperature_array[1] = %d\n", temperature_array[1]);

  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1A;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDF;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  temperature_array[2] = buf[5];
  printf("temperature_array[2] = %d\n", temperature_array[2]);


  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x04;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1A;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDE;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  temperature_array[3] = buf[5];
  printf("temperature_array[3] = %d\n", temperature_array[3]);


  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x05;
  uart_write_bytes(uart_num, (const char*)p, 1);
  byte_hex = 0x03;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1A;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDD;
  uart_write_bytes(uart_num, (const char*)p, 1);   /* 写数据 */
  uart_flush(uart_num);  

  uart_read_bytes(uart_num, (uint8_t*)buf, 8, 100 / portTICK_PERIOD_MS);
  uart_flush(uart_num); 
  //uart_write_bytes(UART0_UX, (const char*)buf, 8);   /* 写数据 */
  uart_flush(UART0_UX); 
  temperature_array[4] = buf[5];
  printf("temperature_array[4] = %d\n", temperature_array[4]);






}


//舵机上电
void LobotSerialServoLoad(uart_port_t uart_num, uint8_t id)
{
  char buf[7];
  buf[0] = buf[1] = LOBOT_SERVO_FRAME_HEADER;
  buf[2] = id;
  buf[3] = 4;
  buf[4] = LOBOT_SERVO_LOAD_OR_UNLOAD_WRITE;
  buf[5] = 1;
  buf[6] = LobotCheckSum(buf);
  uart_write_bytes(uart_num, (const char*)buf, strlen((const char*)buf));   /* 写数据 */
  uart_flush(uart_num);   
}
//舵机掉电
void LobotSerialServoUnload(void)
{

  unsigned char byte_hex;
  unsigned char *p;
  p = &byte_hex; 

  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x01;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  byte_hex = 0x04;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1F;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x00;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDB;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  uart_flush(UART1_UX);  

  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x02;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  byte_hex = 0x04;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1F;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x00;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xDA;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  uart_flush(UART1_UX); 

  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x03;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  byte_hex = 0x04;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1F;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x00;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xD9;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  uart_flush(UART1_UX); 

  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x04;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  byte_hex = 0x04;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1F;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x00;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xD8;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  uart_flush(UART1_UX); 

  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x55;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x05;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  byte_hex = 0x04;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x1F;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0x00;
  uart_write_bytes(UART1_UX, (const char*)p, 1);   /* 写数据 */
  byte_hex = 0xD7;
  uart_write_bytes(UART1_UX, (const char*)p, 1);
  uart_flush(UART1_UX); 

}
